package com.huaxin.hxcloud.find;

import com.huaxin.common.Entity.BaseDTO;
import com.huaxin.common.RequestApi;
import com.huaxin.common.tools.RequestHelper;
import com.huaxin.common.utils.ToastUtil;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 首页 评论点击
 * Created by hebing on 2017/5/9.
 */

public class HttpCommit {

    public void commitLike(int questionId) {
        RequestApi requestApi = RequestHelper.getRequestApi();
        Call<BaseDTO> call = requestApi.commitLikeSwitch(questionId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {
                if (isResponse != null) {
                    isResponse.OnClock(true);
                }
            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                ToastUtil.showToastShort("网络故障,请检查网络");
                if (isResponse != null) {
                    isResponse.OnClock(false);
                }
            }
        });
    }

    public static void commitLike2(int commentId) {
        RequestApi requestApi = RequestHelper.getRequestApi();
        Call<BaseDTO> call = requestApi.commitLikeSwitch2(commentId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {
                if (response.isSuccessful()) {

                } else {

                }
            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                //                ToastUtil.showToastShort("网络故障,请检查网络");
                //                if (isResponse != null) {
                //                    isResponse.OnClock(false);
                //                }
            }
        });
    }

    //收藏
    public void commitCollection(int questionId) {
        Call<BaseDTO> call = RequestHelper.getRequestApi().commitcollectionSwitch(questionId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {
                if (isResponse != null) {
                    isResponse.OnClock(true);
                }
            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                ToastUtil.showToastShort("网络故障,请检查网络");
                if (isResponse != null) {
                    isResponse.OnClock(false);
                }
            }
        });
    }

    public void commitFan(int userId) {
        Call<BaseDTO> call = RequestHelper.getRequestApi().commitFan(userId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {
                if (isResponse != null) {
                    isResponse.OnClock(true);
                }
            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                ToastUtil.showToastShort("网络故障,请检查网络");
                if (isResponse != null) {
                    isResponse.OnClock(false);
                }
            }
        });
    }

    public interface IsResponse {
        void OnClock(boolean flag);
    }

    public IsResponse isResponse;

    public void setIsResponse(IsResponse isResponse) {
        this.isResponse = isResponse;
    }

    public static void comitDelete(int commentId) {
        Call<BaseDTO> call = RequestHelper.getRequestApi().commitDeleteComment(commentId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {

            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                ToastUtil.showToastShort("网络故障");
            }
        });

    }

    public static void comitCircle(int questionId) {
        Call<BaseDTO> call = RequestHelper.getRequestApi().commitDeleteCircle(questionId, null);
        call.enqueue(new Callback<BaseDTO>() {
            @Override
            public void onResponse(Call<BaseDTO> call, Response<BaseDTO> response) {

            }

            @Override
            public void onFailure(Call<BaseDTO> call, Throwable t) {
                ToastUtil.showToastShort("网络故障");
            }
        });

    }
}
